package com.company.project.controller;

import com.company.project.common.utils.DataResult;
import com.company.project.service.HomeService;
import com.company.project.service.HttpSessionService;
import com.company.project.service.MatchProjectService;
import com.company.project.service.MatchTeamService;
import com.company.project.service.SysContentService;
import com.company.project.service.TeamUserService;
import com.company.project.vo.resp.StatisticalData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 首页
 *
 * @author
 * @version V1.0
 * @date 2020年3月18日
 */
@RestController
@RequestMapping("/sys")
@Api(tags = "首页数据")
public class HomeController {
    @Resource
    private HomeService homeService;
    
    @Resource
    private HttpSessionService httpSessionService;
    
    @Resource
	private MatchTeamService matchTeamService;
	
	@Resource
	private MatchProjectService matchProjectService;
	
	@Resource
	private TeamUserService teamUserService;
	
	@Resource
    private SysContentService sysContentService;

    @GetMapping("/home")
    @ApiOperation(value = "获取首页数据接口")
    public DataResult getHomeInfo() {
        //通过access_token拿userId
        String userId = httpSessionService.getCurrentUserId();
        DataResult result = DataResult.success();
        result.setData(homeService.getHomeInfo(userId));
        return result;
    }
    
    @GetMapping("/statistical/data")
    @ApiOperation(value = "获取统计数据")
    public DataResult getStatisticalData() {
    	StatisticalData data = new StatisticalData();
    	
    	int teamValue = matchTeamService.count();
    	int projectValue = matchProjectService.count();
    	int userValue = teamUserService.count();
    	int newsValue = sysContentService.count();
    	data.setNewsValue(newsValue);
    	data.setProjectValue(projectValue);
    	data.setTeamValue(teamValue);
    	data.setUserValue(userValue);

        return DataResult.success(data);
    }
}
